import launch
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, LogInfo, SetEnvironmentVariable
from launch_ros.actions import Node
from launch.substitutions import LaunchConfiguration

def generate_launch_description():
    return LaunchDescription([
        # Declare launch arguments
        DeclareLaunchArgument('ROS_LOCALHOST_ONLY', default_value='0', description='Set ROS_LOCALHOST_ONLY to 0 for multi-machine communication'),

        # Set the environment variable ROS_LOCALHOST_ONLY
        SetEnvironmentVariable(
            name='ROS_LOCALHOST_ONLY',
            value=LaunchConfiguration('ROS_LOCALHOST_ONLY')
        ),

        # Launch the Node
        Node(
            package='robot_data_brige',
            executable='robot_data_brige.py',  # Name of the console script (as defined in setup.py)
            name='robot_data_brige_node',
            namespace='',
            output='screen',
            parameters=[  # Pass parameters to the node
                {'ROS_LOCALHOST_ONLY': LaunchConfiguration('ROS_LOCALHOST_ONLY')}  # Add ROS_LOCALHOST_ONLY as a parameter
            ]
        )
    ])

